package com.ruoyi.admin.service.impl;

import com.ruoyi.admin.mapper.CreditRecordMapper;
import com.ruoyi.admin.mapper.UserTMapper;
import com.ruoyi.admin.service.ICreditRecordService;
import com.ruoyi.common.core.domain.entity.CreditRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 积分记录Service业务层处理
 * 
 * @author xukai
 * @date 2024-12-22
 */
@Service
public class CreditRecordServiceImpl implements ICreditRecordService 
{
    @Autowired
    private CreditRecordMapper creditRecordMapper;

    @Autowired
    private UserTMapper userTMapper;

    /**
     * 查询积分记录
     * 
     * @param type 积分记录主键
     * @return 积分记录
     */
    @Override
    public CreditRecord selectCreditRecordByType(String type)
    {
        //1、获取
        return creditRecordMapper.selectCreditRecordByType(type);
    }

    /**
     * 查询积分记录列表
     * 
     * @param creditRecord 积分记录
     * @return 积分记录
     */
    @Override
    public List<CreditRecord> selectCreditRecordList(CreditRecord creditRecord)
    {
        List<CreditRecord> creditRecords = creditRecordMapper.getCreditRecord();
        return creditRecords;
    }

    /**
     * 新增积分记录
     * 
     * @param creditRecord 积分记录
     * @return 结果
     */
    @Override
    @Transactional
    public int insertCreditRecord(CreditRecord creditRecord)
    {
        creditRecord.setTime(new Date());
        creditRecord.setType("3");
        userTMapper.updateUserCredit(creditRecord.getUserId(),creditRecord.getCredit());
        return creditRecordMapper.insertCreditRecord(creditRecord);
    }

    /**
     * 修改积分记录
     * 
     * @param creditRecord 积分记录
     * @return 结果
     */
    @Override
    public int updateCreditRecord(CreditRecord creditRecord)
    {
        return creditRecordMapper.updateCreditRecord(creditRecord);
    }

    /**
     * 批量删除积分记录
     * 
     * @param types 需要删除的积分记录主键
     * @return 结果
     */
    @Override
    public int deleteCreditRecordByTypes(String[] types)
    {
        return creditRecordMapper.deleteCreditRecordByTypes(types);
    }

    /**
     * 删除积分记录信息
     * 
     * @param type 积分记录主键
     * @return 结果
     */
    @Override
    public int deleteCreditRecordByType(String type)
    {
        return creditRecordMapper.deleteCreditRecordByType(type);
    }
}
